package com.zues.thread.lock.dead.v2;

import com.zues.thread.util.ThreadUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zues
 * @date 2/17/2025 9:14 下午
 */
@Slf4j(topic = "c.TestLiveLock")
public class TestLiveLock {

    static volatile int count = 10;

    static final Object lock = new Object();

    public static void main(String[] args) {

        new Thread(() -> {
            //期望超过20退出循环
            while (count < 20) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                count--;
                log.debug("count:{}", count);

            }
        }, "t1").start();

        new Thread(() -> {
            //期望超过20退出循环
            while (count < 20) {
                try {
                    Thread.sleep(200);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                count++;
                log.debug("count:{}", count);

            }
        }, "t2").start();
    }
}
